package shading;

import java.awt.Color;

import raytracing.RaycastResult;
import structs.Vector3;

public class PhongShader implements IShader {

	@Override
	public Color getShading(RaycastResult result, Vector3 dirToLight, Color lightColor) {
		if (result.normal == null)
			return new Color(0, 0, 0);

		Vector3 r = dirToLight.multiply(-1).plus(result.normal.multiply(2*dirToLight.dotproduct(result.normal)));
		float temp = result.ray.Direction.multiply(-1).dotproduct(r);
		if(temp < 0)
			temp = 0;
		float phongValue = (float) Math.pow(temp, result.specularIntensity);

		float red = (float) result.specularColor.getRed() / 255 * lightColor.getRed() / 255 * phongValue;
		float green = (float) result.specularColor.getGreen() / 255 * lightColor.getGreen() / 255 * phongValue;
		float blue = (float) result.specularColor.getBlue() / 255 * lightColor.getBlue() / 255 * phongValue;
		Color c = new Color(red, green, blue);
		return c;
	}

}
